﻿package mortal.game.view.fashionOnline.view
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.fashionOnline.data.*;
    import mortal.game.view.fashionOnline.util.*;

    public class FashionTagSpr extends GSprite
    {
        private var _category:int;
        private var _fashionType:int;
        private var _isSelected:Boolean;
        private var _fashionState:int = -1;
        private var _type:int;
        private var _selectedBg:GBitmap;
        private var _stateImg:GBitmap;
        private var _btnSpr:GSprite;
        private var _textImg:GBitmap;

        public function FashionTagSpr()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._btnSpr = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._btnSpr);
            this._selectedBg = UIFactory.gBitmap(ImagesConst.SelectedBg2, 0, 0, this._btnSpr);
            this._selectedBg.visible = false;
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.FashionTextBg, 4, 3, this._btnSpr));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.Gift, 10 + 6, 10 + 6, this._btnSpr));
            this._textImg = UIFactory.gBitmap("", 67 + 4, 22 + 4, this._btnSpr);
            this._stateImg = UIFactory.gBitmap(ImagesConst.Text_CanBeActived, 164, 27, this);
            this.mouseChildren = false;
            this.mouseEnabled = true;
            this.buttonMode = true;
            this.addEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            if (!this._isSelected)
            {
                this._selectedBg.visible = true;
                TweenMax.to(this._btnSpr, 0.5, {x:-24});
            }
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            if (!this._isSelected)
            {
                this._selectedBg.visible = false;
                TweenMax.to(this._btnSpr, 0.2, {x:0});
            }
            return;
        }// end function

        public function set isSelected(param1:Boolean) : void
        {
            this._isSelected = param1;
            if (param1)
            {
                this._selectedBg.visible = true;
                this._btnSpr.x = -24;
            }
            else
            {
                this._selectedBg.visible = false;
                TweenMax.to(this._btnSpr, 0.2, {x:0});
            }
            return;
        }// end function

        public function set fashionState(param1:int) : void
        {
            this._fashionState = param1;
            this._btnSpr.filters = [];
            switch(param1)
            {
                case FashionOnlineConst.FashionState_Untake:
                {
                    this._btnSpr.filters = [FilterConst.colorFilter2];
                    this._stateImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_UnActive);
                    break;
                }
                case FashionOnlineConst.FashionState_CanTake:
                {
                    this._stateImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_CanBeActived);
                    break;
                }
                case FashionOnlineConst.FashionState_Taked:
                {
                    if (FashionOnlineUtil.isFashionInUse(this._fashionType))
                    {
                        this._stateImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_InUsing);
                        this._stateImg.y = 27;
                    }
                    else
                    {
                        this._stateImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_HasActive);
                        this._stateImg.y = 4;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get fashionState() : int
        {
            return this._fashionState;
        }// end function

        public function get isSelected() : Boolean
        {
            return this._isSelected;
        }// end function

        public function set type(param1:int) : void
        {
            this._fashionType = param1;
            var _loc_2:* = param1 % 4 == 0 ? (4) : (param1 % 4);
            switch(_loc_2)
            {
                case FashionOnlineConst.FashionType_Weapon:
                {
                    this._textImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_FashionWeapon);
                    break;
                }
                case FashionOnlineConst.FashionType_Headdress:
                {
                    this._textImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_FashionWeapon);
                    break;
                }
                case FashionOnlineConst.FashionType_Wing:
                {
                    this._textImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_FashionWeapon);
                    break;
                }
                case FashionOnlineConst.FashionType_Clothes:
                {
                    this._textImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.Text_FashionWeapon);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get type() : int
        {
            return this._fashionType;
        }// end function

        public function set category(param1:int) : void
        {
            this._category = param1;
            return;
        }// end function

        public function get category() : int
        {
            return this._category;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._selectedBg.dispose(param1);
            this._stateImg.dispose(param1);
            this._btnSpr.dispose(param1);
            this._textImg.dispose(param1);
            this._selectedBg = null;
            this._stateImg = null;
            this._btnSpr = null;
            this._textImg = null;
            this._isSelected = false;
            this._fashionState = -1;
            this._fashionType = 0;
            return;
        }// end function

    }
}
